package com.ctn.information.data.retriever.impl;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import com.ctn.information.data.model.NewsTitle;
import com.ctn.information.data.retriever.Retriever;
import com.ctn.information.data.retriever.Interface.NewsTitleRetriever;
import com.ctn.information.exception.MethodNotSupportException;
import com.ctn.information.util.JsonUtil;

/**
 * Sample Implementation for test only
 * @author Zale
 *
 */
public class NewsTitleRetrieverImpl implements NewsTitleRetriever {
	
	@Override
	public NewsTitle getById(Long id) throws MethodNotSupportException {
		throw new MethodNotSupportException("Not support");
	}

	@Override
	public List<NewsTitle> getAll(boolean asc) throws MethodNotSupportException {
		throw new MethodNotSupportException("Not support");
	}

	@Override
	public List<NewsTitle> getDataByMenuId(Long id,int pageIndex,int count,boolean asc) throws JSONException, Exception{
		JSONObject jsonObj = JsonUtil.getJSON(Retriever.URL_NEWS_TITLE+"?id="+id+"&pageIndex="+pageIndex);
		List<NewsTitle> titles = new ArrayList<NewsTitle>();
		JsonUtil.convertJsonToObj(titles, jsonObj);
		return titles;
	}

	@Override
	public List<NewsTitle> getDataByQueryStr(String queryStr,int pageIndex,int count,boolean asc) throws JSONException, Exception{
		JSONObject jsonObj = JsonUtil.getJSON(Retriever.URL_NEWS_TITLE+"?querystr="+queryStr+"&pageIndex="+pageIndex);
		List<NewsTitle> titles = new ArrayList<NewsTitle>();
		JsonUtil.convertJsonToObj(titles, jsonObj);
		return titles;
	}

}
